/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.sac.be;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Colao
 */
@Entity
@Table(name = "SAC_ASOCIACION_GARANTIA_CREDITO")
@NamedQueries({@NamedQuery(name = "AsociacionGarantiaCredito.findAll", query = "SELECT a FROM AsociacionGarantiaCredito a"), @NamedQuery(name = "AsociacionGarantiaCredito.findByFidGarGarantia", query = "SELECT a FROM AsociacionGarantiaCredito a WHERE a.asociacionGarantiaCreditoPK.fidGarGarantia = :fidGarGarantia"), @NamedQuery(name = "AsociacionGarantiaCredito.findByFidSacEstadoGarantiaAsociada", query = "SELECT a FROM AsociacionGarantiaCredito a WHERE a.asociacionGarantiaCreditoPK.fidSacEstadoGarantiaAsociada = :fidSacEstadoGarantiaAsociada"), @NamedQuery(name = "AsociacionGarantiaCredito.findByFechaRegistro", query = "SELECT a FROM AsociacionGarantiaCredito a WHERE a.fechaRegistro = :fechaRegistro")})
public class AsociacionGarantiaCredito implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected AsociacionGarantiaCreditoPK asociacionGarantiaCreditoPK;
    @Column(name = "FECHA_REGISTRO")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fechaRegistro;
    @JoinColumn(name = "ESTADO", referencedColumnName = "ID_ESTADO_GARANTIA_ASOCIADA")
    @ManyToOne(fetch = FetchType.LAZY)
    private EstadoGarantiaAsociada estado;
    @JoinColumn(name = "FID_SAC_ESTADO_GARANTIA_ASOCIADA", referencedColumnName = "ID_SOLICITUDCREDITO", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private SolicitudCredito solicitudCredito;

    public AsociacionGarantiaCredito() {
    }

    public AsociacionGarantiaCredito(AsociacionGarantiaCreditoPK asociacionGarantiaCreditoPK) {
        this.asociacionGarantiaCreditoPK = asociacionGarantiaCreditoPK;
    }

    public AsociacionGarantiaCredito(long fidGarGarantia, long fidSacEstadoGarantiaAsociada) {
        this.asociacionGarantiaCreditoPK = new AsociacionGarantiaCreditoPK(fidGarGarantia, fidSacEstadoGarantiaAsociada);
    }

    public AsociacionGarantiaCreditoPK getAsociacionGarantiaCreditoPK() {
        return asociacionGarantiaCreditoPK;
    }

    public void setAsociacionGarantiaCreditoPK(AsociacionGarantiaCreditoPK asociacionGarantiaCreditoPK) {
        this.asociacionGarantiaCreditoPK = asociacionGarantiaCreditoPK;
    }

    public Date getFechaRegistro() {
        return fechaRegistro;
    }

    public void setFechaRegistro(Date fechaRegistro) {
        this.fechaRegistro = fechaRegistro;
    }

    public EstadoGarantiaAsociada getEstado() {
        return estado;
    }

    public void setEstado(EstadoGarantiaAsociada estado) {
        this.estado = estado;
    }

    public SolicitudCredito getSolicitudCredito() {
        return solicitudCredito;
    }

    public void setSolicitudCredito(SolicitudCredito solicitudCredito) {
        this.solicitudCredito = solicitudCredito;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (asociacionGarantiaCreditoPK != null ? asociacionGarantiaCreditoPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof AsociacionGarantiaCredito)) {
            return false;
        }
        AsociacionGarantiaCredito other = (AsociacionGarantiaCredito) object;
        if ((this.asociacionGarantiaCreditoPK == null && other.asociacionGarantiaCreditoPK != null) || (this.asociacionGarantiaCreditoPK != null && !this.asociacionGarantiaCreditoPK.equals(other.asociacionGarantiaCreditoPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.upn.sigemfi.sac.be.AsociacionGarantiaCredito[asociacionGarantiaCreditoPK=" + asociacionGarantiaCreditoPK + "]";
    }

}
